﻿using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Read.API.Application.Commends.Incominginformations;

namespace MyMES.Read.API.Application.CommendHandlers.Incominginformations
{
    public class GetMaterialmanagementCommandHandlers : IRequestHandler<GetMaterialmanagementCommands, APIResult<List<Materialmanagement>>>
    {

        private readonly IBaseRepository<Materialmanagement> materialmanagementRepository;

        public GetMaterialmanagementCommandHandlers(IBaseRepository<Materialmanagement> materialmanagementRepository)
        {
            this.materialmanagementRepository = materialmanagementRepository;
        }

        /// <summary>
        /// 查询物料入库信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<Materialmanagement>>> Handle(GetMaterialmanagementCommands request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<Materialmanagement>> result = new APIResult<List<Materialmanagement>>();
                result.Code = APIEnum.查询成功;
                result.Msg = "查询成功";
                var sql = "select * from Materialmanagement where IsDelete = false ORDER BY MId DESC";
                var list = await materialmanagementRepository.SelectAsync(sql);

                result.data = list;
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
